package ipmsg.gui;

import javax.swing.GroupLayout;
import javax.swing.JLabel;

public class GetRecFiles extends javax.swing.JFrame implements InterfaceSetVisible_GetRecFiles
{
  private ipmsg.etc.FileLinkList flist;
  private javax.swing.JCheckBox guiChooseAll;
  private javax.swing.JCheckBox guiCoverExist;
  private javax.swing.JList guiFiles;
  private javax.swing.JButton jButton1;
  private javax.swing.JButton jButton2;
  private JLabel jLabel1;
  private JLabel jLabel10;
  private JLabel jLabel11;
  private JLabel jLabel12;
  private JLabel jLabel2;
  private JLabel jLabel3;
  private JLabel jLabel4;
  private JLabel jLabel5;
  
  public GetRecFiles(ipmsg.etc.FileLinkList flist)
  {
    initComponents();
    setTitle("收到文件");
    this.flist = flist;
    if (this.flist != null) {
      this.guiFiles.setListData(flist.exportFileList());
      this.jLabel10.setText(this.flist.getIp());
      this.jLabel8.setText(ipmsg.etc.GlobalVar.getUser(this.flist.getIp()).getName());
      
      this.jLabel12.setText(flist.getFiles().size() + "");
    } else { dispose();
    }
  }
  







  private void initComponents()
  {
    this.jPanel2 = new javax.swing.JPanel();
    this.jScrollPane1 = new javax.swing.JScrollPane();
    this.guiFiles = new javax.swing.JList();
    this.jPanel1 = new javax.swing.JPanel();
    this.guiChooseAll = new javax.swing.JCheckBox();
    this.guiCoverExist = new javax.swing.JCheckBox();
    this.jButton1 = new javax.swing.JButton();
    this.jButton2 = new javax.swing.JButton();
    this.jPanel3 = new javax.swing.JPanel();
    this.jLabel1 = new JLabel();
    this.jLabel2 = new JLabel();
    this.jLabel3 = new JLabel();
    this.jLabel4 = new JLabel();
    this.jLabel5 = new JLabel();
    this.jLabel6 = new JLabel();
    this.jLabel7 = new JLabel();
    this.jLabel8 = new JLabel();
    this.jLabel9 = new JLabel();
    this.jLabel10 = new JLabel();
    this.jSeparator1 = new javax.swing.JSeparator();
    this.jLabel11 = new JLabel();
    this.jLabel12 = new JLabel();
    this.jMenuBar1 = new javax.swing.JMenuBar();
    this.jMenu1 = new javax.swing.JMenu();
    this.jMenuItem3 = new javax.swing.JMenuItem();
    this.jMenuItem1 = new javax.swing.JMenuItem();
    this.jMenu2 = new javax.swing.JMenu();
    this.jMenuItem2 = new javax.swing.JMenuItem();
    
    setDefaultCloseOperation(0);
    setMinimumSize(new java.awt.Dimension(509, 369));
    addWindowListener(new java.awt.event.WindowAdapter() {
      public void windowClosing(java.awt.event.WindowEvent evt) {
        GetRecFiles.this.formWindowClosing(evt);
      }
      
    });
    this.jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "文件列表", 0, 0, new java.awt.Font("宋体", 0, 10)));
    
    this.jScrollPane1.setAutoscrolls(true);
    
    this.guiFiles.setSelectionMode(0);
    this.guiFiles.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
      public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
        GetRecFiles.this.guiFilesValueChanged(evt);
      }
    });
    this.jScrollPane1.setViewportView(this.guiFiles);
    
    GroupLayout jPanel2Layout = new GroupLayout(this.jPanel2);
    this.jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(this.jScrollPane1, -1, 246, 32767));
    


    jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(this.jScrollPane1, -1, 245, 32767));
    



    getContentPane().add(this.jPanel2, "Center");
    
    this.guiChooseAll.setText("全部接收");
    
    this.guiCoverExist.setText("覆盖同名文件");
    
    this.jButton1.setText("取消");
    this.jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        GetRecFiles.this.jButton1ActionPerformed(evt);
      }
      
    });
    this.jButton2.setText("接收");
    this.jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        GetRecFiles.this.jButton2ActionPerformed(evt);
      }
      
    });
    GroupLayout jPanel1Layout = new GroupLayout(this.jPanel1);
    this.jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(this.guiChooseAll).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(this.guiCoverExist).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 120, 32767).addComponent(this.jButton1).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jButton2).addContainerGap()));
    











    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup().addContainerGap(-1, 32767).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(this.guiChooseAll).addComponent(this.guiCoverExist).addComponent(this.jButton2).addComponent(this.jButton1)).addContainerGap()));
    










    getContentPane().add(this.jPanel1, "South");
    
    this.jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "详细信息", 0, 0, new java.awt.Font("宋体", 0, 10)));
    
    this.jLabel1.setFont(new java.awt.Font("宋体", 1, 12));
    this.jLabel1.setText("类型：");
    
    this.jLabel2.setText(" ");
    
    this.jLabel3.setFont(new java.awt.Font("宋体", 1, 12));
    this.jLabel3.setText("大小：");
    
    this.jLabel4.setText(" ");
    
    this.jLabel5.setFont(new java.awt.Font("宋体", 1, 12));
    this.jLabel5.setText("长度：");
    
    this.jLabel6.setText(" ");
    
    this.jLabel7.setFont(new java.awt.Font("宋体", 1, 12));
    this.jLabel7.setText("发送者：");
    
    this.jLabel8.setText("LanMsg");
    
    this.jLabel9.setFont(new java.awt.Font("宋体", 1, 12));
    this.jLabel9.setText("IP：");
    
    this.jLabel10.setText("0.0.0.0");
    
    this.jLabel11.setFont(new java.awt.Font("宋体", 1, 12));
    this.jLabel11.setText("文件数：");
    
    this.jLabel12.setText("0");
    
    GroupLayout jPanel3Layout = new GroupLayout(this.jPanel3);
    this.jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel3Layout.createSequentialGroup().addComponent(this.jLabel11).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jLabel12, -1, 70, 32767)).addComponent(this.jLabel8, -1, 128, 32767).addComponent(this.jLabel7).addComponent(this.jLabel9).addComponent(this.jLabel10, javax.swing.GroupLayout.Alignment.TRAILING, -1, 128, 32767).addComponent(this.jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, -1, 128, 32767).addGroup(jPanel3Layout.createSequentialGroup().addComponent(this.jLabel1).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jLabel2, -1, 83, 32767)).addGroup(jPanel3Layout.createSequentialGroup().addComponent(this.jLabel3, -1, -1, 32767).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jLabel4, -1, 83, 32767)).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup().addComponent(this.jLabel5).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jLabel6, -1, 83, 32767))).addContainerGap()));
    


























    jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel3Layout.createSequentialGroup().addComponent(this.jLabel7).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jLabel8).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jLabel9).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jLabel10).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(this.jLabel11).addComponent(this.jLabel12)).addGap(11, 11, 11).addComponent(this.jSeparator1, -2, -1, -2).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(this.jLabel2).addComponent(this.jLabel1)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(this.jLabel3).addComponent(this.jLabel4)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(this.jLabel5).addComponent(this.jLabel6)).addContainerGap(70, 32767)));
    





























    getContentPane().add(this.jPanel3, "East");
    
    this.jMenu1.setText("系统");
    
    this.jMenuItem3.setText("发送");
    this.jMenu1.add(this.jMenuItem3);
    
    this.jMenuItem1.setText("退出");
    this.jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        GetRecFiles.this.jMenuItem1ActionPerformed(evt);
      }
    });
    this.jMenu1.add(this.jMenuItem1);
    
    this.jMenuBar1.add(this.jMenu1);
    
    this.jMenu2.setText("聊天");
    
    this.jMenuItem2.setText("和对方聊天");
    this.jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        GetRecFiles.this.jMenuItem2ActionPerformed(evt);
      }
    });
    this.jMenu2.add(this.jMenuItem2);
    
    this.jMenuBar1.add(this.jMenu2);
    
    setJMenuBar(this.jMenuBar1);
    
    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width - 434) / 2, (screenSize.height - 369) / 2, 434, 369);
  }
  
  private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt)
  {
    exit();
  }
  




  private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {}
  



  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
  {
    exit();
  }
  

  private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
  {
    int choice = -1;
    if (this.guiChooseAll.isSelected()) {
      choice = this.flist.getFiles().size();
    }
    else if (this.guiFiles.getSelectedValue() != null) {
      choice = ipmsg.etc.UtilityGlobal.atoi(((String)this.guiFiles.getSelectedValue()).trim());
    }
    else {
      UtilityGui.showNotice(this, "请标记您需要接收的文件!"); return;
    }
    

    String savePath;
    
    if ((savePath = UtilityGui.chooseFile(this, false)) == null) { return;
    }
    setVisible(false);
    new RecvingFile(this.flist, choice, savePath, this, this.guiCoverExist.isSelected()).setVisible(true);
  }
  

  private void guiFilesValueChanged(javax.swing.event.ListSelectionEvent evt)
  {
    int selectLen = this.guiFiles.getSelectedIndices().length;
    if (selectLen == 1) {
      ipmsg.etc.FileNode fnode = (ipmsg.etc.FileNode)this.flist.getFiles().get(this.guiFiles.getSelectedIndex());
      
      if (fnode.getFileKind() == 2) {
        this.jLabel2.setText("目录");
      } else if (fnode.getFileKind() == 1)
        this.jLabel2.setText("普通文件"); else {
        this.jLabel2.setText("未知类型");
      }
      this.jLabel6.setText(fnode.getFileLen() + " B");
      this.jLabel4.setText(getSize(fnode.getFileLen()));
    }
  }
  
  private void formWindowClosing(java.awt.event.WindowEvent evt)
  {
    exit();
  }
  

  private JLabel jLabel6;
  
  private JLabel jLabel7;
  
  private JLabel jLabel8;
  
  private JLabel jLabel9;
  
  private javax.swing.JMenu jMenu1;
  
  private javax.swing.JMenu jMenu2;
  
  private javax.swing.JMenuBar jMenuBar1;
  
  private javax.swing.JMenuItem jMenuItem1;
  
  private javax.swing.JMenuItem jMenuItem2;
  
  private javax.swing.JMenuItem jMenuItem3;
  
  private javax.swing.JPanel jPanel1;
  
  private javax.swing.JPanel jPanel2;
  
  private javax.swing.JPanel jPanel3;
  
  private javax.swing.JScrollPane jScrollPane1;
  
  private javax.swing.JSeparator jSeparator1;
  
  public void exit()
  {
    ipmsg.etc.Command com = new ipmsg.etc.Command(97);
    com.setIp(this.flist.getIp());
    com.setAdditional(this.flist.getPacketNo() + "");
    ipmsg.network.UtilityNet.sendUdpPacket(com);
    dispose();
  }
  
  private String getSize(long size) {
    if (size >> 12 <= 0L) return size + " B";
    if (size >> 22 <= 0L) return (size >> 10) + " KB";
    if (size >> 32 <= 0L) return (size >> 20) + " MB";
    return (size >> 30) + " GB";
  }
  
  public void enableVisible() {
    this.guiFiles.setListData(this.flist.exportFileList());
    if (this.guiFiles.getModel().getSize() == 0) dispose(); else {
      setVisible(true);
    }
  }
}
